package bricolot.exporter;

import java.util.Iterator;

import bricolot.Garage;
import bricolot.Moto;
import bricolot.Reparation;
import bricolot.Societe;
import bricolot.Voiture;

public class BricolotoExporterV1 extends AXmlExporter implements
		IBricolotoExporter {

	public BricolotoExporterV1(String anXmlFilename) {
		super(anXmlFilename);
		this.println("<!Doctype Societe SESTEM 'Bricoloto.dtd'>");
	}

	public void visitSociete(Societe aSociete) {
		this.println("<Societe>");
		this.tab(2);
		this.print("<nom>");
		this.print(aSociete.getNom());
		this.println("</nom>");
		this.tab(2);
		this.print("<adresse>");
		this.print(aSociete.getAdresse());
		this.println("</adresse>");

		Iterator<Garage> garageIt = aSociete.getGarages().iterator();
		while (garageIt.hasNext()) {
			garageIt.next().accept(this);
		}

		this.printNewLine();
		this.println("</Societe>");

	}

	public void visitGarage(Garage aGarage) {
		this.tab(2);
		this.println("<Garage>");
		this.tab(4);
		this.print("<nom>");
		this.print(aGarage.getNom());
		this.println("</nom>");
		this.tab(4);
		this.print("<adresse>");
		this.print(aGarage.getAdresse());
		this.println("</adresse>");

		Iterator<Reparation> reparationIt = aGarage.getReparations().iterator();
		while (reparationIt.hasNext()) {
			reparationIt.next().accept(this);
		}

		this.printNewLine();
		this.tab(2);
		this.println("</Garage>");
	}

	public void visitVoiture(Voiture aVoiture) {
		this.tab(4);
		this.println("<Voiture>");
		this.addReparationInfo(aVoiture);
		this.tab(6);
		this.print("<ct>");
		this.print(aVoiture.getCt());
		this.println("</ct>");
		this.tab(4);
		this.println("</Voiture>");
	}

	public void visitMoto(Moto aMoto) {
		this.tab(4);
		this.println("<Moto>");
		this.addReparationInfo(aMoto);
		this.tab(6);
		this.print("<sd>");
		this.print(Boolean.valueOf(aMoto.isSd()).toString());
		this.println("</sd>");
		this.tab(4);
		this.println("</Moto>");
	}

	public void addReparationInfo(Reparation aReparation) {
		this.tab(6);
		this.print("<date>");
		this.print(aReparation.getDate());
		this.println("</date>");
		this.tab(6);
		this.print("<motif>");
		this.print(aReparation.getMotif());
		this.println("</motif>");
	}

	public String getContents() {
		return super.getContents();
	}

	public void closeStream() {
		super.closeStream();
	}
}
